lib/commit: Unref repo on success
authorGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>
Tue, 16 Aug 2022 22:54:29 +0000 (19:54 -0300)
committerGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>
Tue, 16 Aug 2022 22:54:29 +0000 (19:54 -0300)
commit092421fabf3ae573b80370c924882cdcc6815af9
tree23995b50ff56ab86d620c390b0ab2bdc88109e6d
parent26a546886a5ef48ed11551f69c7178277f752d9d
lib/commit: Unref repo on success

Commit 540e60c3 introduced _ostree_repo_auto_transaction_new(), a
private constructor to OstreeRepoAutoTransaction, by factoring out
some code from _ostree_repo_auto_transaction_start(). This factored
code increased the refcount of the 'repo' variable.

Subsequent commit 71304e854c made ostree_repo_prepare_transaction()
use ths newly introduced constructor. However, in this function, the
happy path assumed no ref was taken, and therefore did not unref it.
Commit 71304e854c didn't add the corresponding unref either.

This leaks a reference to OstreeRepo when calling
ostree_repo_prepare_transaction().

Plug this leak by using g_clear_object() to clear the repo field
of OstreeRepoAutoTransaction, instead of simply setting it to NULL.

Closes https://github.com/flatpak/flatpak/issues/4928
src/libostree/ostree-repo-commit.c